import java.text.StringCharacterIterator;


public class SQLadaptString {
	
	public static String adapt( String text ){
		final StringBuffer sb = new StringBuffer( text.length() * 2 );
		final StringCharacterIterator iterator = new StringCharacterIterator( text );

		char character = iterator.current();

		while( character != StringCharacterIterator.DONE ){
		if( character == '"' ) sb.append( "\\\"" );
		else if( character == '\'' ) sb.append( "\\\'" );
		else if( character == '\\' ) sb.append( "\\\\" );
		else if( character == '\n' ) sb.append( "\\n" );
		else if( character == '{' ) sb.append( "\\{" );
		else if( character == '}' ) sb.append( "\\}" );
		else sb.append( character );

		character = iterator.next();
		}

		return sb.toString();
		}

}
